import AxiosMethods from "@/util/AxiosMethods"
const state = {
    comments: []
}
const mutations = {
    setComments(state, comments) {
        state.comments = comments
        // console.log("完成初始化评论:", state.comments)
    }
}
const actions = {
    // 获取评论
    async getComments({ commit },id) {
        const params = {
            pid: Number(id),
        }
        try{
            const response = await AxiosMethods.post('/comments/select', params)
            if(response.data.code === 1){
                // console.log("获取评论成功:",response.data.data)
                return response.data.data
            }
        }catch(error){
            console.log(error)
        }
    },
    // 提交评论
    async saveComments({ commit },data) {
        try{
            const response = await AxiosMethods.post('/comments/add', data)
            if(response.data.code === 1){
                console.log("评论成功")
            }
        }catch(error){
            console.log(error)
        }
    },
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}